package cn.maxhou.service.impl;

import cn.maxhou.entity.Supplier;
import cn.maxhou.entity.SysUser;
import cn.maxhou.mapper.SupplierMapper;
import cn.maxhou.mapper.SysUserMapper;
import cn.maxhou.service.SupplierService;
import cn.maxhou.util.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {

    private static final Logger LOGGER= LoggerFactory.getLogger(SupplierServiceImpl.class);

    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public List<Supplier> getSupplierList() {
        return supplierMapper.getSupplierList();
    }

    @Override
    public Page<Supplier> findpage(Supplier entity, Integer pageNo, Integer pageSize) {
        Page<Supplier> page=new Page<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        //查询总数,计算总页数
        page.setTotalCount(supplierMapper.count(entity).intValue());
        //查询分页数据
        List<Supplier> data = supplierMapper.getpage(entity, page.offset(), pageSize);
        page.setData(data);
        return page;
    }

    @Override
    public int save(Supplier entity) {
        if (entity.getId()==null) {
            return supplierMapper.insert(entity);
        }else {
            return supplierMapper.update(entity);
        }
    }

    @Override
    public Supplier getById(Long id) {
        return supplierMapper.getById(id);
    }

    @Override
    public int deleteById(Long id) {
        return supplierMapper.deleteById(id);
    }

    @Override
    public Supplier getSupplierBysupCode(String supCode) {
        return supplierMapper.getSupplierBysupCode(supCode);
    }
}
